/*
 * @Author: viivLgr 
 * @Date: 2018-06-06 15:44:57 
 * @Last Modified by: viivLgr
 * @Last Modified time: 2018-06-06 16:54:19
 */
import React from 'react';
import FileUpload from './react-fileupload.jsx';

class FileUploader extends React.Component {
    render() {
        /*set properties*/
        const options = {
            baseUrl: '/manage/product/upload.do',
            fileFieldName: 'upload_file',
            dataType: 'json',
            chooseAndUpload: true,
            uploadSuccess: (res) => {
                this.props.onSuccess(res.data)
            },
            uploadError: (err) => {
                this.props.onError(err.message || '上传图片出错啦')
            }
        }
        /*Use FileUpload with options*/
        /*Set two dom with ref*/
        return (
            <FileUpload options={options}>
                <button ref="chooseAndUpload" className="btn btn-xs btn-default">请选择图片</button>
            </FileUpload>
        )
    }
}

export default FileUploader;
